package org.bdware.repository.storage;

import org.bdware.doip.core.model.metadata.MetaDO;

public class DCMIMetadata {

    public String title;
    public String description;
    public String date;
    public String format;
    public String language;
    public String source;
    public String topic;
    public String coverage;
    public TYPE type;

    public MetaDO toDoMetadata(String doID){
        MetaDO dom = new MetaDO(doID);
        dom.addAttribute("title",title);
        dom.addAttribute("description",description);
        dom.addAttribute("date",date);
        dom.addAttribute("format",format);
        dom.addAttribute("language",language);
        dom.addAttribute("source",source);
        dom.addAttribute("topic",topic);
        dom.addAttribute("coverage",coverage);
        dom.addAttribute("type",type.getName());
        return dom;
    }

    public static DCMIMetadata fromDoMetadata(MetaDO metaDO){
        DCMIMetadata dcmi = new DCMIMetadata();
        dcmi.title = metaDO.getMetadata("title");
        dcmi.description = metaDO.getMetadata("description");
        dcmi.date = metaDO.getMetadata("date");
        dcmi.format = metaDO.getMetadata("format");
        dcmi.language = metaDO.getMetadata("language");
        dcmi.source = metaDO.getMetadata("source");
        dcmi.topic = metaDO.getMetadata("topic");
        dcmi.coverage = metaDO.getMetadata("coverage");
        dcmi.type = TYPE.getType(metaDO.getMetadata("title"));
        return dcmi;
    }


    public enum TYPE {
        Collection("collection"),
        PhysicalObject("PhysicalObject"),
        Dataset("Dataset"),
        Event("Event"),
        Sound("Sound"),
        Text("Text"),
        Image("Image"),
        StillImage("StillImage"),
        MovingImage("MovingImage"),
        Service("Service"),
        Software("Software"),
        InteractiveResources("InteractiveResources"),
        UnKnown("UnKnow");

        private final String name;

        TYPE(String displayName){this.name = displayName;
        }

        public static TYPE getType(String typeStr){
            for (TYPE type : TYPE.values()) {
                if (type.getName().equals(typeStr)) {
                    return type;
                }
            }
            return TYPE.UnKnown;
        }

        public String getName() {
            return name;
        }
    }
}
